package components;

import org.w3c.tidy.Tidy;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;

/**
 * Created by IntelliJ IDEA.
 * User: Zlobec
 * Date: 02.03.2006
 * Time: 14:06:29
 * To change this template use File | Settings | File Templates.
 */
public class WmlTidy extends Tidy {
    public WmlTidy() {
        super();
        setMakeClean(false);
        setWraplen(99);
        setXmlOut(false);
        setXHTML(false);
        setMakeClean(true);
        setDocType("omit");
        setTidyMark(false);
        setQuoteNbsp(false);
        setCharEncoding(org.w3c.tidy.Configuration.UTF8);
        setNumEntities(true);
        setQuoteMarks(true);
        setLogicalEmphasis(false);
        setEncloseText(true);
        setAltText("empty");
        setWriteback(true);
        setQuiet(true);
        setDropEmptyParas(true);
        setDropFontTags(true);

    }

    public String clean(String inputText) throws UnsupportedEncodingException {

        ByteArrayInputStream stream = new ByteArrayInputStream(inputText.getBytes("UTF-8"));
        ByteArrayOutputStream outXmlStream = new ByteArrayOutputStream();
        parse(stream, outXmlStream);

        return new String(outXmlStream.toByteArray(),"UTF-8");
    }

}
